package com.capgemini.mulefocus.transformer;

import java.util.List;

import org.mule.api.transformer.TransformerException;
import org.mule.transformer.AbstractTransformer;
import org.mule.transformer.types.DataTypeFactory;

import com.mongodb.BasicDBObject;

/**
 * Returns the number of hits in a collection. 
 * 
 * @author Jan-Erik Carlsen (Capgemini)
 *
 */
public class MongoDBStringToTweetCountTransformer extends AbstractTransformer{

	
	public MongoDBStringToTweetCountTransformer() {
		super();
		this.registerSourceType(DataTypeFactory.create(List.class));
	    this.setReturnDataType(DataTypeFactory.create(String.class));
	}
	
	@SuppressWarnings("unchecked")
	@Override
	protected Object doTransform(Object src, String enc)
			throws TransformerException {
		List<BasicDBObject> sourceList = (List<BasicDBObject>) src;
		String tweetCount = (sourceList == null) ? "Zero" : Integer.toString(sourceList.size());
		
		return tweetCount;
	}

}
